package com.hn.kiss.admin.compoent;

import com.google.common.collect.Maps;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;
import org.thymeleaf.spring5.view.ThymeleafViewResolver;

import javax.annotation.Resource;
import java.util.Map;

/**
 * thymeleaf全局变量设置
 * @author dnkj011
 *
 */
@Component
public class WebMvcConfigurerAdapter {

    @Resource
    private Environment env;

    @Resource
    private void configureThymeleafStaticVars(ThymeleafViewResolver viewResolver) {
        if(viewResolver != null) {
            Map<String, Object> vars = Maps.newHashMap();
            vars.put("web_root", env.getProperty("server.servlet.context-path"));
            viewResolver.setStaticVariables(vars);
        }
    }
 
}
